package com.black.platform.datapower;

import com.black.common.auth.UserContextHolder;
import com.black.common.feign.PlatformFeignClient;
import com.black.common.vo.ShareUserVo;
import com.black.common.web.ApiResponse;
import com.black.common.web.ApiResponseBuilder;
import com.black.platform.permission.service.bz.PermissionService;
import com.black.common.vo.PermissionVo;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Set;
import java.util.stream.Collectors;

/**
 * @author linwenfeng
 */
@Service
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class PlatformFeignClientImpl implements PlatformFeignClient {

    private final PermissionService permissionService;

    @Override
    public ApiResponse<ShareUserVo> findUserByUsername(String username) {
        return null;
    }

    @Override
    public ApiResponse<Set<String>> getAllPermissionsByUser(String systemCode) {
        return ApiResponseBuilder.ok(permissionService.getAllPermissionsByUser(UserContextHolder.getUserId(), systemCode, false)
                .stream().map(PermissionVo::getPermissionCode).collect(Collectors.toSet()));
    }

    @Override
    public ApiResponse<Set<String>> getAllDataPermissionsByUser(String systemCode) {
        return ApiResponseBuilder.ok(permissionService.getAllDataPermissionsByUser(UserContextHolder.getUserId(), systemCode)
                .stream().map(PermissionVo::getPermissionCode).collect(Collectors.toSet()));
    }

    @Override
    public ApiResponse<Set<String>> getUserDataPower() {
        return ApiResponseBuilder.ok(null);
    }

    @Override
    public ApiResponse<ShareUserVo> findUserByOtherId(String otherId, String idType) {
        return null;
    }

    @Override
    public ApiResponse<ShareUserVo> register(ShareUserVo shareUserVo) {
        return null;
    }
}

